package com.xjh.him.netty;

import io.netty.channel.ChannelHandlerContext;

import java.util.ArrayList;
import java.util.List;

public interface HandlerCallback {
    List<HandlerListener> listenerList = new ArrayList<>();

    /**
     * 订阅回调
     * @param listener
     */
    public static void subscribe(HandlerListener listener) {
        listenerList.add(listener);
    }

    /**
     * 推送消费
     * @return
     */
    public default Boolean pushConsume(ChannelHandlerContext ctx, Object msg) {
        Boolean consume = false;
        for (HandlerListener listener : listenerList) {
            consume |= listener.consume(ctx, msg);
        }
        return consume;
    }
}
